const mysql = require('mysql');

//创建连接
var connection = mysql.createConnection({
    host    : 'localhost',
    user    : 'root',
    password: 'root',
    database:'demhem'
});

//执行连接
connection.connect();

//操作数据库
// connection.query(`INSERT INTO student(name,age,money) VALUES('小马','12','1212')`,(error, result) => {
//     if(error) {
//         console.log('err =====>',error);
//         console.log('出错了');
//     };
//     if(result.offectedRows == 1){
//         console.log('insert 成功')
//     };
//     console.log('result === >',result);
// })

let data = {
    name: 'root',
    age: '23',
    money:'100'
}
connection.query(`INSERT INTO student SET ?`,data,(error,result) => {
    if(error) {
        console.log('err ====>',error);
        console.log('出错了')
    };
    if(result.affectedRows == 1){
        console.log('insert 成功')
    }
})

//关闭连接
connection.end();